<%--
  Created by IntelliJ IDEA.
  User: 恒少
  Date: 2021/3/10
  Time: 9:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>入库审批</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script src="layui/layui.js"></script>
</head>
<!-- L2Dwidget.js L2D网页动画人物 -->
<script src="https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js"></script>
<script>
    L2Dwidget.init({
        "model": { "jsonPath":"https://unpkg.com/live2d-widget-model-koharu@1.0.5/assets/koharu.model.json", "scale": 1, "hHeadPos":0.5, "vHeadPos":0.618 },
        "display": { "position": "right", "width": 250, "height": 300, "hOffset":0, "vOffset": 0 },
        "mobile": { "show": true, "scale": 0.5 },
        "react": { "opacityDefault": 0.7, "opacityOnHover": 0.2 }
    });
</script>
<body>
<div style="margin: 0 43% ;color: #4E5465;font-size: 50px " >入库审核</div>

<div class="demoTable">
    搜索ID：
    <div class="layui-inline">
        <input class="layui-input" name="orderid" id="demoReload" autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload">根据订单号搜索</button>
</div>

<table class="layui-hide" id="test" lay-filter="test"></table>
<div id="up" style="display: none">
    <table class="layui-hide" id="test1" lay-filter="test1"></table>
</div>


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">

    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">查看详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="del">入库</a>
</script>

<script type="text/html" id="state">
    {{#  if(d.orderstatus ==1){ }}
    <button class="layui-btn layui-btn-sm">未处理</button>
    {{#  } else { }}
    <button class="layui-btn layui-btn-sm layui-btn-danger">处理中</button>
    {{#  } }}
</script>


<script>
    layui.use(['table', 'jquery', 'form', 'layer'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;

        function showTable() {
            table.render({
                elem: '#test'
                , url: '${pageContext.request.contextPath}/buy/query1'
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    , layEvent: 'LAYTABLE_TIPS'
                    , icon: 'layui-icon-tips'
                }]
                , title: '用户数据表'

                , cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'orderid', title: '订单ID', fixed: 'left', unresize: true, sort: true}
                    , {field: 'w_name', title: '发布人员'}
                    , {field: 'p_name', title: '采购人员'}
                    , {field: 'orderdate', title: '采购日期'}
                    , {field: 'actualcount', title: '采购数量'}
                    // ,{field:'inprice', title:'单价'}
                    , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
                ]]
                , id: 'testReload'
                , page: false
            });
        }

        $(function () {
            showTable();
        });

        //搜索时执行表格重载方法
        var $ = layui.$, active = {
            reload: function () {
                var demoReload = $('#demoReload').val();
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        orderid: demoReload
                    }
                }, 'data');
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            }
            ;
        });


        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
                $.ajax({
                    type: 'post',
                    url: '${pageContext.request.contextPath}/order/Storage',
                    data: {orderid: data.orderid},
                    dataType: 'json',
                    success: function (result) {
                        if (result.code == 1) {
                            layer.msg(result.msg, {icon: 1});
                            showTable();
                        } else {
                            layer.msg(result.msg, {icon: 5});
                        }
                    }
                });
            } else if (obj.event === 'edit') {
                //订单详情回显
                //修改
                layer.open({
                    type: 1,
                    title: "标题",
                    fixed: true,
                    resize: false,
                    moveOut: true,
                    totalRow: true,
                    offset: 'auto',
                    area: ['950px', '300px'],
                    content: $('#up'),
                    success: function () {
                        table.render({
                            id: 'idSc',
                            elem: '#test1'
                            , method: 'post'
                            , url: '${pageContext.request.contextPath}/buy/queryById?orderid=' + data.orderid
                            , toolbar: '#toolbarDemo'
                            , title: '用户数据表'
                            , totalRow: true
                            , cols: [[
                                {type: 'checkbox', fixed: 'left'}
                                // ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, }
                                , {
                                    field: 'orderid',
                                    title: '订单ID',
                                    fixed: 'left',
                                    unresize: true,
                                    sort: true,
                                    totalRowText: '合计'
                                }
                                , {field: 'bookname', title: '书名'}
                                , {field: 'author', title: '作者'}
                                , {field: 'press', title: '出版社'}
                                , {field: 'b_count', title: '采购数量', totalRow: true}
                                , {field: 't_price', title: '金额', totalRow: true}
                            ]]
                            , page: false
                        });
                    }
                });
            }
        });

    });
</script>


</body>
</html>
